package com.example.erp.service.impl;

import java.util.List;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;

import com.example.erp.entity.Book;
import com.example.erp.repository.BookRepository;
import com.example.erp.service.BookService;

import jakarta.annotation.Resource;

/**
 * 图书服务接口原生实现.
 */
@Service
public class BookServiceImpl implements BookService {

	@Resource
	private BookRepository bookRepository;

	@Override
	@Tool(name = "findBooksByTitle", description = "根据书名模糊查询图书，支持部分标题匹配")
	public List<Book> findBooksByTitle(@ToolParam(description = "书名关键词") String title) {
		return bookRepository.findByTitleContaining(title);
	}

	@Override
	@Tool(name = "findBooksByAuthor", description = "根据作者精确查询图书")
	public List<Book> findBooksByAuthor(@ToolParam(description = "作者姓名") String author) {
		return bookRepository.findByAuthor(author);
	}

	@Override
	@Tool(name = "findBooksByCategory", description = "根据图书分类精确查询图书")
	public List<Book> findBooksByCategory(@ToolParam(description = "图书分类") String category) {
		return bookRepository.findByCategory(category);
	}

	@Override
	@Tool(name = "findAllBooks", description = "列出所有图书信息")
	public List<Book> findAllBooks() {
		return bookRepository.findAllBooks();
	}

	@Override
	@Tool(name = "countBook", description = "列出图书数量")
	public int countBook() {
		return bookRepository.countBook();
	}

	@Override
	@Tool(name = "addBook", description = "新增书籍信息")
	public int addBook(@ToolParam(description = "书籍信息") Book book) {
		return bookRepository.addBook(book);
	}

	@Override
	@Tool(name = "updateBook", description = "更新书籍信息")
	public int updateBook(@ToolParam(description = "书籍信息") Book book) {
		return bookRepository.updateBook(book);
	}

	@Override
	@Tool(name = "deleteBook", description = "删除书籍信息")
	public int deleteBook(@ToolParam(description = "书籍信息") Book book) {
		return bookRepository.deleteBook(book);
	}
}
